import sys
from PIL import Image

path = sys.argv[1]
out_path = "./output.bin"

try:
    out_path = sys.argv[2]
except:
    pass

# 打开图片
image = Image.open(path)
# 获取图片的宽度和高度
width, height = image.size

alpha = 1

f = None

with open(out_path, "wb") as file:
    file.write(width.to_bytes(4, 'big'))
    file.write(height.to_bytes(4, 'big'))

    for y in range(height):
        for x in range(width):
            # 获取(x, y)位置的像素值
            pixel = image.getpixel((x, y))
            pixel = pixel[0] << 24 | pixel[1] << 16 | pixel[2] << 8 | pixel[3]
            # pixel = "0x" + hex(pixel)[2:].upper()
            file.write(pixel.to_bytes(4, 'big'))
            # print(pixel)

print(width, height)